package com.all.play.mypsm.home.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.all.play.mypsm.R;
import com.all.play.mypsm.home.bean.HomeResaultBeanData;
import com.all.play.mypsm.utils.Constants;
import com.bumptech.glide.Glide;

import java.util.List;

/**
 * Created by 聪明一只哈 on 2018/3/31.
 */

public class HotVhAdapter extends BaseAdapter {
    private Context mContext;
    private List<HomeResaultBeanData.ResultBean.HotInfoBean> hot_info;

    public HotVhAdapter(Context mContext, List<HomeResaultBeanData.ResultBean.HotInfoBean> hot_info) {


        this.mContext = mContext;
        this.hot_info = hot_info;
    }

    @Override
    public int getCount() {
        return hot_info==null?0:hot_info.size();
    }

    @Override
    public Object getItem(int position) {
        return hot_info.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        HotViewHolde hvh;
        if(convertView==null){
            hvh=new HotViewHolde();
            convertView=View.inflate(mContext, R.layout.item_hot_grid_view,null);
            hvh.iv_hot=convertView.findViewById(R.id.iv_hot);
            hvh.tv_name=convertView.findViewById(R.id.tv_name);
            hvh.tv_price=convertView.findViewById(R.id.tv_price);

            convertView.setTag(hvh);
        }else {
            hvh= (HotViewHolde) convertView.getTag();
        }

        HomeResaultBeanData.ResultBean.HotInfoBean hotInfoBean = hot_info.get(position);
        if(hot_info!=null){
            Glide.with(mContext).load(Constants.BASE_URl_IMAGE+hotInfoBean.getFigure()).into(hvh.iv_hot);

            hvh.tv_name.setText(hotInfoBean.getName());
            hvh.tv_price.setText("￥"+hotInfoBean.getCover_price());
        }


        return convertView;
    }

    static class HotViewHolde{
        ImageView iv_hot;
        TextView tv_name,tv_price;
    }
}
